package com.ch3;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 *interrupt
 */
@Slf4j(topic = "c.Thread")
public class ThreadDemo_08 {
    public static void main(String[] args) throws InterruptedException {
    t1();
    }



    public static void t1() throws InterruptedException {
        Thread thread = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
                log.debug("do sth after sleep");
            } catch (InterruptedException e) {
                log.debug("sleep interrupted");
                e.printStackTrace();
            }
        }, "t1");
        thread.start();
        TimeUnit.SECONDS.sleep(1);
        log.debug("before interrupt........... ,isInterrupted:{}",thread.isInterrupted());
        thread.interrupt();
        TimeUnit.SECONDS.sleep(1);
        log.debug("after interrupt........... ,isInterrupted:{}",thread.isInterrupted());
        log.debug("after interrupt........... ,isInterrupted:{}",thread.isInterrupted());

    }


}
